#include <stdlib.h>
#include <stdio.h>
#include "ringbuffer.h"

int main()
{
	int BufferDescription0, BufferDescription1, BufferDescription2, bd3;
	int a, b, c;
	a = 1;b = 2, c = 3;
	int err;
	int index;
	/* crete RingBuffer*/
	printf("RingBufferInit & RingBufferExit test\n");
	BufferDescription0 = RingBufferInit(2, sizeof(char), cover);	printf("BufferDescription0(0) = %d\n", BufferDescription0);
	BufferDescription1 = RingBufferInit(2, sizeof(int), cover);	printf("BufferDescription1(1) = %d\n", BufferDescription1);
	/*delete and crete RingBuffer*/
	RingBufferExit(BufferDescription0);
	BufferDescription2 = RingBufferInit(2, sizeof(int*), cover);	printf("BufferDescription2(0) = %d\n", BufferDescription2);
	BufferDescription0 = RingBufferInit(2, sizeof(int), cover);	printf("BufferDescription0(2) = %d\n", BufferDescription0);

	/* bd(10)&err(10) = -1 */
	for (index = 3; index < 10; index++)
	{
		bd3 = RingBufferInit(2, sizeof(int), cover);printf("bd(%d) = %d\t", index, bd3);
	}
	bd3 = RingBufferInit(2, sizeof(int), cover);
	if (bd3 == -1)
		printf("creat RingBuffer error\n");
	for (index = 0; index < 10; index++)
	{
		err = RingBufferExit(index);printf("err(%d) = %d\t", index, err);
	}
	err = RingBufferExit(0);
	if (bd3 == -1)
		printf("This RingBuffer does not exist\n");

	/* send data */
	printf("SendToRingBuffer & GetFromRingBuffer test\n");
	BufferDescription0 = RingBufferInit(2, sizeof(int), cover);
	err = SendToRingBuffer(BufferDescription0, &a);	printf("err(0) = %d\t", err);
	err = SendToRingBuffer(BufferDescription0, &b);	printf("err(0) = %d\t", err);
	err = SendToRingBuffer(BufferDescription0, &c);
	err = SendToRingBuffer(BufferDescription0, &c);	printf("err(0) = %d\n", err);
	/* get data */
	err = GetFromRingBuffer(BufferDescription0, &c);	printf("c(2) = %d\t", c);printf("err(0) = %d\n", err);
	err = GetFromRingBuffer(BufferDescription0, &c);	printf("c(3) = %d\t", c);printf("err(0) = %d\n", err);
	/* empty */
	err = GetFromRingBuffer(BufferDescription0, &c);

}


